﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _2011DBProject
{
    public partial class Bench : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            updateStats();
        }

        private void updateStats()
        {
            try
            {
                SqlDataSource1.DataBind();
                DataList1.DataBind();
                Label tmpLabel = (Label)(DataList1.Controls[0].Controls[2].FindControl("CHARACTER_NAMELabel"));
                lblCharacterName.Text = tmpLabel.Text;

                tmpLabel = (Label)(DataList1.Controls[0].Controls[3].FindControl("TIREDNESSLabel"));
                lblTire.Text = tmpLabel.Text;
            }
            catch (Exception)
            {
                throw;
            }
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                DataSet1TableAdapters.CHARACTERTableAdapter taCharacter = new _2011DBProject.DataSet1TableAdapters.CHARACTERTableAdapter();
                taCharacter.Connection.ConnectionString = Settings.strConnectionString;
                DataSet1.CHARACTERDataTable dtCharacter = taCharacter.GetDataByServerNoCharacterName(Settings.decServer, Settings.strCharacterName);
                if (dtCharacter.Count > 0)
                {
                    DataSet1.CHARACTERRow row = dtCharacter[0];
                    if (row.TIREDNESS > 0)
                    {
                        decimal factor = 0;
                        factor = row.STRENGTH * Convert.ToDecimal(0.3);
                        if (factor < 1) factor = 1;
                        row.TIREDNESS -= factor;
                        taCharacter.Update(dtCharacter);
                        updateStats();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void btnGoLogout_onclick(object sender, EventArgs e)
        {
            Session.Clear();
            Response.Redirect("Default.aspx");
        }
        protected void btnGoServer_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Server.aspx");
        }
        protected void btnGoCharacter_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Character.aspx");
        }
        protected void btnGoChannel_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Channel.aspx");
        }
        protected void btnGoMain_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Gameroom.aspx");
        }
    }
}
